*** One-Child Policy, Marriage Distortion, and Welfare Loss ***
*** by Wei Huang, Yinghao Pan and Yi Zhou ***

clear all 
set more off
set scheme s1color
cap log close 
graph set window fontface "Times New Roman"

set niceness 10
gl MAIN = "F:\Dropbox"

gl path1 = "$MAIN/Census"
gl path2 = "$MAIN/Marriage/Working_data"
gl path3 = "$MAIN/Marriage/Restat/dataverse_files/Results" 
gl path4 = "$MAIN/Marriage/Restat/dataverse_files/Graphics" 

***** Appendix Table A20 *****

use  "$path2/ocp_uhs_reg", clear 

keep if lninc_per > 7 & lninc_per <12
keep if lnexp_per > 6.5 & lnexp_per <12
keep if lnconsump_per > 6 & lnconsump_per <11.5
drop if saving < -80 
set more off
gen head = head1 == 1 & head2 == 1
gen female_hd = women*head
egen female_hh = max(female_hd), by(dcode hcode prov year)
drop female_hd

gen smoke_wine = smoke_share + wine_share


gl FINE_VAR_1 =  "fine_16_25" 

gl CONTROL_1 = " women#age year_birth  prov##c.year_birth" 

egen f_p = mean(women), by(dcode hcode year)
keep if age > 25 & age <= 55 
keep if year_birth <= 1980

gen HM = (han_p > 0.1 & han_p < 0.9) & (married == 1)
gen HOMO = married - HM

replace HM = HM* 100 
replace HOMO = HOMO* 100 

gen unmarried = (1- married)*100


cap drop mino_policy 
gen mino_policy = .
gen rural = 0

replace mino_policy = 	0		 if prov == 	11	
replace mino_policy = 	0		 if prov == 	12	
replace mino_policy = 	0		 if prov == 	13	
replace mino_policy = 	0		 if prov == 	14	
replace mino_policy = 	1		 if prov == 	15	
replace mino_policy = 	1		 if prov == 	21	  & rural == 1
replace mino_policy = 	1		 if prov == 	21	  & rural == 0

replace mino_policy = 	0		 if prov == 	22	
replace mino_policy = 	0		 if prov == 	23	
replace mino_policy = 	0		 if prov == 	31	
replace mino_policy = 	0		 if prov == 	32	
replace mino_policy = 	1		 if prov == 	33	 & rural == 1
replace mino_policy = 	0		 if prov == 	33	 & rural == 0

replace mino_policy = 	0		 if prov == 	34	
replace mino_policy = 	1		 if prov == 	35	 

replace mino_policy = 	0		 if prov == 	36	
replace mino_policy = 	0		 if prov == 	37	
replace mino_policy = 	0		 if prov == 	41	
replace mino_policy = 	0		 if prov == 	42	
replace mino_policy = 	1		 if prov == 	43	  & rural == 1
replace mino_policy = 	0		 if prov == 	43	  & rural == 0

replace mino_policy = 	1		 if prov == 	44	  & rural == 1
replace mino_policy = 	0		 if prov == 	44	  & rural == 0

replace mino_policy = 	0		 if prov == 	45	
replace mino_policy = 	1		 if prov == 	46	  & rural == 1
replace mino_policy = 	0		 if prov == 	46	  & rural == 0

replace mino_policy = 	1		 if prov == 	50	  & rural == 1
replace mino_policy = 	0		 if prov == 	50	  & rural == 0

replace mino_policy = 	1		 if prov == 	51	
replace mino_policy = 	1		 if prov == 	52	  & rural == 1
replace mino_policy = 	0		 if prov == 	52	  & rural == 0

replace mino_policy = 	1		 if prov == 	53	 

replace mino_policy =   1		 if prov ==		54 

replace mino_policy = 	0		 if prov == 	61	
replace mino_policy = 	1		 if prov == 	62	  & rural == 1
replace mino_policy = 	0		 if prov == 	62	  & rural == 0

replace mino_policy = 	1		 if prov == 	63	
replace mino_policy = 	1		 if prov == 	64	
replace mino_policy = 	1		 if prov == 	65	  & rural == 1
replace mino_policy = 	0		 if prov == 	65	  & rural == 0


cap erase "$path3/OCP_married_uhs.xls"
cap erase "$path3/OCP_married_uhs.txt"

foreach sample in "1" "unmarried == 0" {
foreach eth in " han  ==1 " " han == 0 "{
foreach policy in "1"" mino_policy  ==1 " " mino_policy == 0 "{
foreach FINE_VAR in"$FINE_VAR_1"  {
foreach y_var in "unmarried" "HOMO""HM" {


reghdfe `y_var'  c.(`FINE_VAR') if `sample' & `eth' & `policy', a($CONTROL_1) cluster(prov)
su `y_var' if  `sample' & `eth' & `policy'
local mean = r(mean)
outreg2 using "$path3/OCP_married_uhs.xls",append dec(3) bracket adds(Women, `mean') ctit("`y_var' & `sample' & `eth' & `policy'") dec(3)
}
}
}
}
}
